package com.group9.handinhand.service.so;

import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.ArrayUtils;

import com.group9.handinhand.dao.model.Offer;
/**
 * Class for service of offer
 *
 */
public class OfferSO extends ActivitySO {
	
	private Date expirationDate;
	
	private Set<UserSO> moderators = new HashSet<UserSO>();
	
	private Set<OfferPostSO> posts = new HashSet<OfferPostSO>();
	/**
	 * converts to offer model object
	 * @param ignoreProperties
	 * @return
	 */
	public Offer convertToModelObject(String... ignoreProperties) {
		Offer model = (Offer) convert(new Offer(), 
			(String[]) ArrayUtils.addAll(ignoreProperties, new String[]{"community","creator","posts","service","goods","moderators"}));
		if( ! Arrays.asList(ignoreProperties).contains("community"))
			if(super.getCommunity() != null)
			model.setCommunity(super.getCommunity().convertToModelObject(new String[]{"moderators", "posts", "events","requests","offers"}));
		if( ! Arrays.asList(ignoreProperties).contains("creator"))
			if(super.getCreator() != null)
			model.setCreator(super.getCreator().convertToModelObject(new String[]{"socialUsers"}));
		if (!Arrays.asList(ignoreProperties).contains("posts"))
			for (OfferPostSO post : posts) {
				model.getPosts().add(post.convertToModelObject());
			}
		if( ! Arrays.asList(ignoreProperties).contains("service"))
			if(super.getService() != null)
				model.setService(super.getService().convertToModelObject());
		if( ! Arrays.asList(ignoreProperties).contains("goods"))
			if(super.getGoods() != null)
				model.setGoods(super.getGoods().convertToModelObject());
		if( ! Arrays.asList(ignoreProperties).contains("moderators"))
		for (UserSO user : moderators) {
			model.getModerators().add(user.convertToModelObject(new String[]{"socialUsers"}));
		}
		return model;
	}

	public Set<OfferPostSO> getPosts() {
		return posts;
	}

	public void setPosts(Set<OfferPostSO> posts) {
		this.posts = posts;
	}

	public Date getExpirationDate() {
		return expirationDate;
	}

	public void setExpirationDate(Date expirationDate) {
		this.expirationDate = expirationDate;
	}

	public Set<UserSO> getModerators() {
		return moderators;
	}

	public void setModerators(Set<UserSO> moderators) {
		this.moderators = moderators;
	}

	@Override
	public String toString() {
		return "OfferSO [expirationDate=" + expirationDate + ", moderators="
				+ moderators + ", posts=" + posts + "]";
	}
	
	

}
